package com.freecat.xmqgct;

import android.Manifest;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.CircleOptions;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.Stroke;
import com.baidu.mapapi.model.LatLng;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;

import com.freecat.xmqgct.app.MyApp;
import com.freecat.xmqgct.mvp.model.entity.MapPointEntity;
import com.freecat.xmqgct.mvp.model.entity.Project;
import com.freecat.xmqgct.mvp.presenter.MainPresenter;
import com.freecat.xmqgct.mvp.ui.activity.BaseActivity;
import com.freecat.xmqgct.mvp.ui.activity.MapActivity;
import com.freecat.xmqgct.mvp.ui.activity.SearchActivity;
import com.freecat.xmqgct.utils.Constant;
import com.freecat.xmqgct.utils.CustomItemDecoration;
import com.freecat.xmqgct.utils.MapFixUtil;
import com.freecat.xmqgct.utils.SimpleRecyclerAdapter;
import com.freecat.xmqgct.utils.Tools;
import com.qw.soul.permission.SoulPermission;
import com.qw.soul.permission.bean.Permission;
import com.qw.soul.permission.bean.Permissions;
import com.qw.soul.permission.callbcak.CheckRequestPermissionsListener;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;
import io.objectbox.Box;
import me.jessyan.art.mvp.IView;
import me.jessyan.art.mvp.Message;
import me.jessyan.art.utils.ArtUtils;

public class MainActivity extends BaseActivity<MainPresenter> implements IView {


    @BindView(R.id.iv_avatar)
    CircleImageView ivAvatar;
    @BindView(R.id.iv_add)
    ImageView ivAdd;
    @BindView(R.id.et_search)
    EditText etSearch;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.ll_empty)
    LinearLayout llEmpty;

    @BindView(R.id.line_main_jgxm)
    LinearLayout line_main_jgxm;
    @BindView(R.id.line_main_fjgxm)
    LinearLayout line_main_fjgxm;


    //正在工作项目
    @BindView(R.id.tv_main_working_project_01)
    TextView tv_working_project_01;

    //已完成项目
    @BindView(R.id.tv_main_end_project_01)
    TextView tv_end_project_01;

    //建委监管项目
    @BindView(R.id.tv_main_working_project_jw)
    TextView tv_working_project_jw;

    //南江项目
    @BindView(R.id.tv_main_working_project_nj)
    TextView tv_working_project_nj;

    @BindView(R.id.tv_main_search)
    ImageView tv_main_search;


    @BindView(R.id.tab_layout_main)
    TabLayout tab_layout_main;

    private long exitTime;
    private String[] typeArray = new String[]{"销毁", "取消"};
    private int selectIndex;
    private String zhlx;


    String pagesize="100";
    String pageno="1";
    String flag="1";


    String path="xmqgct";

    String projectpath="project";

    final int RESULT_CODE=101;
    final int REQUEST_CODE=1;

//    map_main_view
    @BindView(R.id.map_main_view)
    MapView map_main_view;

    private BaiduMap baiduMap;

    double Apotlon;
    double Apotlat;


    int countx=1;

    private LocationClient locationClient;
    LocationClientOption locationOption = new LocationClientOption();

    private List<OverlayOptions> overlayOptionses=new ArrayList<OverlayOptions>();
    private MarkerOptions options;


    List<MapPointEntity> points = new ArrayList<MapPointEntity>();

    private Box<Project> ProjectBeanBox;

    List<Project> projectList;

    View map_line_view;

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_main;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        setTitle("项目基本信息");
        System.out.println("登录成功");
        SPUtils utils = SPUtils.getInstance(Constant.SP_CONFIG);
        zhlx = utils.getString(Constant.ZH_LX);
        String avatar = utils.getString(Constant.USER_AVATAR);
        if (TextUtils.isEmpty(avatar)) {
            ivAvatar.setImageResource(R.drawable.icon_unit);
        } else {
            Tools.loadImage(mContext, avatar, ivAvatar);
        }
        requestPermission();
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        String mainfilepath="xmqgct";
        String datapath=String.valueOf(year);

        if (Tools.hasSdcard()){
             String str=Tools.getSDPath();
             Tools.createPath(str+"/"+path);

        }
        if (Tools.hasSdcard()){
            String str=Tools.getSDPath();
            Tools.createPath(str+"/"+path+"/"+datapath);
        }
        if (Tools.hasSdcard()){
            String str=Tools.getSDPath();
            Tools.createPath(str+"/"+path+"/"+datapath+"/"+projectpath);
        }

        ProjectBeanBox = MyApp.getBoxStore().boxFor(Project.class);
        projectList=ProjectBeanBox.query().build().find();

        if (projectList.size()<=0&&projectList!=null){
            firstint();
        }else {
            for (int i=0;i<projectList.size();i++){

                System.out.println(projectList.get(i).getMc());
            }
        }
        initLocationOption();
        baiduMap = map_main_view.getMap();
    }

    private void setListener() {

        tab_layout_main.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                switch (tab.getPosition()) {
                    case 0:

                        break;
                    case 1:

                        break;
                }

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {


            }
        });


        etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
//                    String text = etSearch.getText().toString().trim();
//                    boolean offline = SPUtils.getInstance(Constant.SP_CONFIG).getBoolean(Constant.OFFLINE);
//                    boolean connected2 = NetworkUtils.isConnected();
//                    /*if (offline) {*/
//                    if (!connected2) {
//                        getOfflineData(text);
//                    } else {
//                        mPresenter.getProjectList(Message.obtain(MainActivity.this, new String[]{rybh, "1", zhlx, text}));
//                    }
                    KeyboardUtils.hideSoftInput(MainActivity.this);
                }
                return false;
            }
        });
        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
//                String text = etSearch.getText().toString().trim();
//                boolean offline = SPUtils.getInstance(Constant.SP_CONFIG).getBoolean(Constant.OFFLINE);
//                boolean connected2 = NetworkUtils.isConnected();
//                /*if (offline) {*/
//                if (!connected2) {
//                    getOfflineData(text);
//                } else {
//                    mPresenter.getProjectList(Message.obtain(MainActivity.this, new String[]{rybh, "1", zhlx, text}));
//                }
            }
        });
    }



    private void requestPermission() {
        Permissions permissions = Permissions.build(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION);
        SoulPermission.getInstance().checkAndRequestPermissions(permissions, new CheckRequestPermissionsListener() {
            @Override
            public void onAllPermissionOk(Permission[] allPermissions) {

            }

            @Override
            public void onPermissionDenied(Permission[] refusedPermissions) {
                requestPermission();
            }
        });
    }


    private void setAdapter() {
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new CustomItemDecoration(10));

    }

    @Nullable
    @Override
    public MainPresenter obtainPresenter() {
        return new MainPresenter(ArtUtils.obtainAppComponentFromContext(this));
    }

    @Override
    public void showLoading() {
        progressDialog.show();
    }

    @Override
    public void hideLoading() {
        progressDialog.dismiss();
    }

    @Override
    public void showMessage(@NonNull String message) {

    }

    @Override
    public void handleMessage(@NonNull Message message) {
        switch (message.what) {
//            case MainPresenter.GET_PROJECT_LIST:

//                break;


        }
    }



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }




    @OnClick({R.id.iv_avatar, R.id.iv_add, R.id.ll_empty,R.id.tv_main_working_project_01,R.id.tv_main_end_project_01,R.id.tv_main_working_project_jw,R.id.tv_main_working_project_nj,R.id.tv_main_search})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_avatar:

                break;
            case R.id.iv_add:

                break;
            case R.id.tv_main_working_project_01:

                break;
            case R.id.tv_main_end_project_01:

                break;
            case R.id.tv_main_working_project_jw:

                break;
            case R.id.tv_main_working_project_nj:

                break;
            case  R.id.tv_main_search:
                System.out.println("搜索结果");
                recyclerView.setVisibility(View.VISIBLE);
                /*
                *
                * */
                Intent intent = new Intent(this, SearchActivity.class);

                ArtUtils.startActivity(intent);
                break;

        }
    }



    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK
                && event.getAction() == KeyEvent.ACTION_DOWN) {
            if ((System.currentTimeMillis() - exitTime) > 1000) {
                //弹出提示，可以有多种方式
                ToastUtils.showShort("再按一次退出程序");
                exitTime = System.currentTimeMillis();
            } else {
                ActivityUtils.finishAllActivities();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }



    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==REQUEST_CODE) {
            if(resultCode==RESULT_CODE) {

            }
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
//        initLocationOption();
//        baiduMap = map_main_view.getMap();
        map_main_view.onResume();
//        initLocationOption();
    }

    @Override
    protected void onPause() {
        super.onPause();
        map_main_view.onPause();
    }

    @Override
    protected void onDestroy() {
        map_main_view.onDestroy();
        super.onDestroy();
    }


    private void initLocationOption() {
        locationClient = new LocationClient(getApplicationContext());
//声明LocationClient类实例并配置定位参数
//        LocationClientOption locationOption = new LocationClientOption();
        MainActivity.MyLocationListener myLocationListener = new MainActivity.MyLocationListener();
//注册监听函数
        locationClient.registerLocationListener(myLocationListener);
        locationOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
//可选，默认gcj02，设置返回的定位结果坐标系，如果配合百度地图使用，建议设置为bd09ll;
        locationOption.setCoorType("bd09ll");
        //可选，默认false，设置是否开启Gps定位
        locationOption.setOpenGps(true);
//可选，默认0，即仅定位一次，设置发起连续定位请求的间隔需要大于等于1000ms才是有效的
        locationOption.setScanSpan(3000);
//可选，设置是否需要地址信息，默认不需要
        locationOption.setIsNeedAddress(true);
//可选，设置是否需要地址描述
        locationOption.setIsNeedLocationDescribe(false);
//可选，设置是否需要设备方向结果
        locationOption.setNeedDeviceDirect(true);
//可选，默认false，设置是否当gps有效时按照1S1次频率输出GPS结果
        locationOption.setLocationNotify(false);
//可选，默认true，定位SDK内部是一个SERVICE，并放到了独立进程，设置是否在stop的时候杀死这个进程，默认不杀死
        locationOption.setIgnoreKillProcess(true);
//可选，默认false，设置是否需要POI结果，可以在BDLocation.getPoiList里得到
        locationOption.setIsNeedLocationPoiList(true);
//可选，默认false，设置是否收集CRASH信息，默认收集
        locationOption.SetIgnoreCacheException(false);
//可选，默认false，设置定位时是否需要海拔信息，默认不需要，除基础定位版本都可用
        locationOption.setIsNeedAltitude(true);
//设置打开自动回调位置模式，该开关打开后，期间只要定位SDK检测到位置变化就会主动回调给开发者，该模式下开发者无需再关心定位间隔是多少，定位SDK本身发现位置变化就会及时回调给开发者
        locationOption.setOpenAutoNotifyMode();
////设置打开自动回调位置模式，该开关打开后，期间只要定位SDK检测到位置变化就会主动回调给开发者
//        locationOption.setOpenAutoNotifyMode(1000,10, LocationClientOption.LOC_SENSITIVITY_HIGHT);
        locationClient.setLocOption(locationOption);
        locationClient.start();
    }


    public class MyLocationListener extends BDAbstractLocationListener {
        @Override
        public void onReceiveLocation(BDLocation location) {


            //此处的BDLocation为定位结果信息类，通过它的各种get方法可获取定位相关的全部结果
            //以下只列举部分获取经纬度相关（常用）的结果信息
            //更多结果信息获取说明，请参照类参考中BDLocation类中的说明
//            baiduMap.clear();
//            //获取纬度信息


//            Toast.makeText(MapActivity.this,"Apotlat0"+Apotlat+"__"+Apotlat, Toast.LENGTH_SHORT).show();
//           LatLng latLng = new LatLng(latitude, longitude);
//            LatLng latLng = new LatLng(latitude1, longitude1);
//            BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker);
//            MarkerOptions markerOptions = new MarkerOptions().position(latLng).draggable(true)
//                    .icon(bitmapDescriptor);
//            baiduMap.addOverlay(markerOptions);
//            ReverseGeoCodeOption op = new ReverseGeoCodeOption();
//            op.location(latLng);
//            geoCoder.reverseGeoCode(op);
//            MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newLatLngZoom(latLng, 15);
//            baiduMap.animateMapStatus(mapStatusUpdate);
//            locationClient.stop();


//            HashMap marsTobaidu= MapFixUtil.marsTobaidu(location.getLongitude(),location.getLatitude());
//            Apotlon = (double) marsTobaidu.get("baidu_point_lon");
//            Apotlat= (double) marsTobaidu.get("baidu_point_lat");
            HashMap marsTobaidu= MapFixUtil.marsTobaidu(location.getLongitude(),location.getLatitude());
            Apotlon =location.getLongitude();
            Apotlat= location.getLatitude();

            if(projectList.size()>0){

                for (Project pr:projectList){
                    MapPointEntity MPE_PR=new MapPointEntity();

                    double lon=Double.valueOf(pr.getJd());
                    double lat=Double.valueOf(pr.getWd());
                    MPE_PR.setPointLat(lat);
                    MPE_PR.setPointLon(lon);
                    MPE_PR.setPointName(pr.getMc());
                    points.add(MPE_PR);
                }
            }
            System.out.println("location.getLongitude()=="+location.getLongitude()+"location.getLatitude()==="+location.getLatitude());
            if (countx<=1){
                if (Apotlat>0&&Apotlon>0){
                    MapPointEntity MPE2=new MapPointEntity();
                    MPE2.setPointName("当前坐标点");
                    MPE2.setPointLat(Apotlat);
                    MPE2.setPointLon(Apotlon);
                    points.add(MPE2);
                }
                if (location == null || map_main_view == null){
                    return;
                }
                MyLocationData locData = new MyLocationData.Builder().accuracy(location.getRadius())
                        // 此处设置开发者获取到的方向信息，顺时针0-360
                        .direction(100).latitude(Apotlat).longitude(Apotlon).build();
                baiduMap.setMyLocationData(locData);
                LatLng ll = new LatLng(Apotlat, Apotlon);
                MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
                baiduMap.animateMapStatus(u);
                generateMarker(points);
            }

//            countx++;


//            LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude());
//            MyLocationData locData = new MyLocationData.Builder().accuracy(location.getRadius())// 构造定位数据
//                    // 此处设置开发者获取到的方向信息，顺时针0-360
//                    .direction(100).latitude(location.getLatitude())
//                    .longitude(location.getLongitude()).build();
//            baiduMap.setMyLocationData(locData);// 设置定位数据
//            if (isFirstLoc) {
//                isFirstLoc = false;
//                MapStatus.Builder builder = new MapStatus.Builder();
//                builder.zoom(28.0f).target(latLng);
//                baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
//
//                if (location.getLocType() == BDLocation.TypeGpsLocation) {// GPS定位结果
//                    Toast.makeText(MapActivity.this,location.getAddrStr(), Toast.LENGTH_SHORT).show();
////                    Log.d("TypeGpsLocation location", location.toString());
//                }else if (location.getLocType() == BDLocation.TypeOffLineLocation) {// 离线定位结果
//                    Toast.makeText(MapActivity.this,location.getAddrStr(), Toast.LENGTH_SHORT).show();
//                }else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {// 网络定位结果
//                    Toast.makeText(MapActivity.this,location.getAddrStr(), Toast.LENGTH_SHORT).show();
//                } else if (location.getLocType() == BDLocation.TypeServerError) {
//                    Toast.makeText(MapActivity.this, "服务器错误，请检查",Toast.LENGTH_SHORT).show();
//                } else if (location.getLocType() == BDLocation.TypeNetWorkException) {
//                    Toast.makeText(MapActivity.this, "网络错误，请检查",Toast.LENGTH_SHORT).show();
//                } else if (location.getLocType() == BDLocation.TypeCriteriaException) {
//                    Toast.makeText(MapActivity.this,"仪器模式错误，请检查是否飞行", Toast.LENGTH_SHORT).show();
//                }
//            }
//            updateView(latLng);//更新自定义标记显示
//            locationClient.stop();
        }
    }




    public void generateMarker(List<MapPointEntity> ListPoint) {

//
//        Double lat1=Double.valueOf("29.58836605012687");
//        Double lot2=Double.valueOf("106.53594518736195");

//        LatLng nl=new LatLng(lat1,lot2);

//        ListPoint.add(nl);

        int x=0;
        for (MapPointEntity point:ListPoint) {
            x++;
            System.out.println( "x"+x+"当前坐标"+point.getPointLat()+"__"+point.getPointLon());


//                         Hotel hotel = (Hotel) iterator.next();
//                         LatLng ll = new LatLng(point);
            map_line_view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.baidumap_point_custom, null);
            // ImageView img_hotel_image=
            // (ImageView)view.findViewById(R.id.img_hotel_image);
            // DownloadImageTask(img_hotel_image).execute(hotel.getHotelImageUrl());
            TextView baidumap_custom_text = (TextView) map_line_view.findViewById(R.id.baidumap_custom_text);
            baidumap_custom_text.setText(point.getPointName());
            LatLng ll = new LatLng(point.getPointLat(),point.getPointLon());
            BitmapDescriptor markerIcon = BitmapDescriptorFactory.fromBitmap(getViewBitmap(map_line_view));
//                         String title="点";
//                         Bundle bundle = new Bundle();
//                         bundle.putSerializable("POT", title+x);

            BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.marker);//构建Marker图标
            OverlayOptions oo = new MarkerOptions().position(ll).icon(markerIcon).zIndex(9).draggable(true);
            baiduMap.addOverlay(oo);
            MapStatus.Builder builder = new MapStatus.Builder();
            builder.zoom(15.0f).target(ll);
            baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));

            if (point.getPointName().equals("基准开孔点")){
                OverlayOptions ooCircle = new CircleOptions().fillColor(0x384d73b3)
                        .center(ll).stroke(new Stroke(3, 0x784d73b3))
                        .radius(5);
                baiduMap.addOverlay(ooCircle);

            }

            baiduMap.setOnMarkerClickListener(onMarkerClickListener);

        }

    }


    BaiduMap.OnMarkerClickListener onMarkerClickListener = new BaiduMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {


            System.out.println("marker.getPosition().latitude==="+marker.getPosition().latitude+"marker.getPosition().longitude==="+marker.getPosition().longitude+"marker.getTitle().toString()");
//            System.out.println("marker.getPosition().latitudeE6==="+marker.getPosition().latitudeE6+"marker.getPosition().longitudeE6==="+marker.getPosition().longitudeE6);

            ToastUtils.showShort("经度=="+marker.getPosition().latitude+"===维度==="+marker.getPosition().longitude);
            return false;
        }
    };




    private void updateView(LatLng latLng) {
        baiduMap.clear();//先清除图层
        LatLng point = latLng;

        if (point != null) {
            BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.marker);//构建Marker图标
            options = new MarkerOptions().position(point).icon(bitmap);// 构建MarkerOption，用于在地图上添加Marker
            overlayOptionses.add(options);
            baiduMap.addOverlays(overlayOptionses);// 在地图上添加Marker数组，并显示
            MapStatus.Builder builder = new MapStatus.Builder();
            builder.zoom(28.0f).target(latLng);
            baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
        } else {
            Toast.makeText(MainActivity.this,"没有获取到GPS坐标请检查", Toast.LENGTH_SHORT).show();
        }
    }


    //自定义百度点位图
    private Bitmap getViewBitmap(View addViewContent) {

        addViewContent.setDrawingCacheEnabled(true);

        addViewContent.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
        addViewContent.layout(0, 0, addViewContent.getMeasuredWidth(), addViewContent.getMeasuredHeight());

        addViewContent.buildDrawingCache();
        Bitmap cacheBitmap = addViewContent.getDrawingCache();
        Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

        return bitmap;
    }



    //初始化生成项目离线数据
    public void firstint(){

//            * 项目名称
//                * 项目地址
//                * 项目信息
//        开工时间
//                竣工时间
//        项目业主
//                * 管理单位
//                * 设计单位
//                * 施工单位
//                * 监理单位
//                * 造价单位
//        项目经度
//                * 项目维度
//                *
        String strmc="重庆西站";
        String strads1="重庆市沙坪坝区凤中路168号";
        String kgsj1="2020年1月";
        String jgsj1="2021年3月";
        String xmyz1="重庆市政";
        String gldw1="汽修管理";
        String jldw1="汽修监理";
        String sgdw1="重庆一建";
        String zjdw1="重庆造价";
        String jd1="106.442446";
        String wd1="29.50634";
        String info1="";


        String strmc2="重庆北站";
        String strads2="重庆市渝北区昆仑大道51号附8号";
        String kgsj2="2020年1月";
        String jgsj2="2021年3月";
        String xmyz2="重庆市政";
        String gldw2="建工管理";
        String jldw2="建工监理";
        String sgdw2="重庆二建";
        String zjdw2="重庆造价";
        String jd2="106.557317";
        String wd2="29.615452";
        String info2="";


        String strmc3="重庆南站";
        String strads3="重庆市九龙坡区黄桷坪铁路二村222号";
        String kgsj3="2020年1月";
        String jgsj3="2021年3月";
        String xmyz3="重庆市政";
        String gldw3="建工管理";
        String jldw3="建工监理";
        String sgdw3="重庆二建";
        String zjdw3="重庆造价";
        String jd3="106.545858";
        String wd3="29.502101";
        String info3="";


        String strmc4="重庆火车东站开成路施工项目";
        String strads4="重庆市南岸区玉马路与广茂大道交汇处东北侧";
        String kgsj4="2020年1月";
        String jgsj4="2021年3月";
        String xmyz4="重庆市综合交通枢纽（集团）有限公司";
        String gldw4="重庆市住建委";
        String jldw4="重庆市市政设计研究院有限公司";
        String sgdw4="重庆市施工有限公司";
        String zjdw4="重庆监理有限公司";
        String jd4="106.673345";
        String wd4="29.492459";
        String info4="重庆东站铁路综合交通枢纽高铁经济区基础设施工程（开成路、兴塘路拓宽及东延伸段、东侧集散通道）位于重庆东站片区，重庆东站是国家“八纵八横”高速铁路主通道中包海、京昆、夏渝、沿江四条主通道的交汇点，是重庆联系“长江经济带”和国际陆海贸易新通道沿线省市的重要枢纽，是重庆铁路枢纽四个客运主站之一。\n" +
                "\n" +
                "\n" +
                "重庆东站铁路综合交通枢纽高铁高新区基础设施工程（开成路、兴塘路拓宽及东延伸段、东侧集散通道）项目包含三条骨架铁路：开成路、兴塘路拓宽及东延伸段、东侧集散通道。三条线路一起范围总长13.74km。";

        Project pr1=new Project();
        pr1.setMc(strmc);
        pr1.setDz(strads1);
        pr1.setKgsj(kgsj1);
        pr1.setJgsj(jgsj1);
        pr1.setXmyz(xmyz1);
        pr1.setGldw(gldw1);
        pr1.setSgdw(sgdw1);
        pr1.setZjdw(zjdw1);
        pr1.setJldw(jldw1);
        pr1.setJd(jd1);
        pr1.setWd(wd1);

        Project pr2=new Project();
        pr2.setMc(strmc2);
        pr2.setDz(strads2);
        pr2.setKgsj(kgsj2);
        pr2.setJgsj(jgsj2);
        pr2.setXmyz(xmyz2);
        pr2.setGldw(gldw2);
        pr2.setSgdw(sgdw2);
        pr2.setZjdw(zjdw2);
        pr2.setJldw(jldw2);
        pr2.setJd(jd2);
        pr2.setWd(wd2);

        Project pr3=new Project();
        pr3.setMc(strmc3);
        pr3.setDz(strads3);
        pr3.setKgsj(kgsj3);
        pr3.setJgsj(jgsj3);
        pr3.setXmyz(xmyz3);
        pr3.setJldw(jldw3);
        pr3.setGldw(gldw3);
        pr3.setSgdw(sgdw3);
        pr3.setZjdw(zjdw3);
        pr3.setJd(jd3);
        pr3.setWd(wd3);



        Project pr4=new Project();
        pr4.setMc(strmc4);
        pr4.setDz(strads4);
        pr4.setKgsj(kgsj4);
        pr4.setJgsj(jgsj4);
        pr4.setXmyz(xmyz4);
        pr4.setGldw(gldw4);
        pr4.setSgdw(sgdw4);
        pr4.setZjdw(zjdw4);
        pr4.setJldw(jldw4);
        pr4.setJd(jd4);
        pr4.setWd(wd4);
        pr4.setXx(info4);

        List<Project> ListPro=new ArrayList<>();
        ListPro.add(pr1);
        ListPro.add(pr2);
        ListPro.add(pr3);
        ListPro.add(pr4);

        ProjectBeanBox.put(ListPro);



    }


}
